package com.chinasoft.dish.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.chinasoft.dish.domain.Dish;
import com.chinasoft.dish.mapper.DishMapper;
import com.chinasoft.dish.service.DishService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 菜单业务层
 */
@Service("dishService")
public class DishServiceImpl implements DishService {

    @Resource
    private DishMapper dishMapper;

    /**
     * 查询所有菜品
     * @return
     */
    @Override
    public List<Dish> findAll(Map<String,Object> map) {
        Dish dish = BeanUtil.fillBeanWithMap(map, new Dish(), false);
        return dishMapper.findAll(dish);
    }

    /**
     * 根据id查询菜品
     * @param bid
     * @return
     */
    @Override
    public List<Dish> findOne(String bid) {
        return dishMapper.findOne(bid);
    }

    /**
     * 添加菜品
     * @param dish
     */
    @Override
    public void addDish(Dish dish) {
        dishMapper.addDish(dish);
    }

    /**
     * 根据商家id和菜品名删除菜品
     * @param map
     */
    @Override
    public void delDish(Map<String, Object> map) {
//        使用Hutool的BeanUtil将Map转为javaBean
        Dish dish = BeanUtil.fillBeanWithMap(map, new Dish(), false);
        dishMapper.delDish(dish);
    }

    /**
     * 修改菜品
     * @param dish
     */
    @Override
    public void updateDish(Dish dish) {
        dishMapper.updateDish(dish);
    }
}
